package welsir.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import welsir.entity.dos.RotationChart;
import welsir.entity.dos.Setting;
import welsir.entity.vo.ResultMessage;
import welsir.mapper.RotationChartMapper;
import welsir.mapper.SettingMapper;
import welsir.util.ResultUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Genius
 * @date 2023/03/08 15:21
 **/
@RestController
@RequestMapping("/Setting")
@Validated
@Api(value = "网站设置",tags = {"网站设置接口"})
public class SettingController {

    @Resource
    private SettingMapper settingMapper;

    @Resource
    private RotationChartMapper rotationChartMapper;

    @ApiOperation(value = "修改设置")
    @ApiImplicitParam(name = "setting",value = "设置",required = true)
    @PostMapping("/setSetting")
    public ResultMessage<Integer> setSetting(
            @RequestBody Setting setting
    ) {
        return ResultUtil.data(settingMapper.updateById(setting));
    }

    @ApiOperation(value = "获取oss配置")
    @GetMapping("/getCosSetting")
    public ResultMessage<Setting> getCosSetting(
    ) {
        return ResultUtil.data(settingMapper.selectOne(null));
    }

    @ApiOperation(value = "修改设置")
    @ApiImplicitParam(name = "setting",value = "设置",required = true)
    @PostMapping("/setSettingCos")
    public ResultMessage<Integer> setSettingCos(
            @RequestBody Setting setting
    ) {
        return ResultUtil.data(settingMapper.update(setting,null));
    }

    @ApiOperation(value = "获取全部轮播图")
    @ApiImplicitParam(name = "setting",value = "设置",required = true)
    @GetMapping("/getAllDispositionCarousel")
    public ResultMessage<List<RotationChart>> getAllDispositionCarousel(
    ) {
        return ResultUtil.data(rotationChartMapper.selectList(null));
    }

    //修改轮播图
    @ApiOperation(value = "修改轮播图")
    @ApiImplicitParam(name = "setting",value = "设置",required = true)
    @PostMapping("/setRotationChart")
    public ResultMessage<Object> setRotationChart(@RequestBody RotationChart rotationChart){
        return ResultUtil.data(rotationChartMapper.updateById(rotationChart));
    }

    //添加轮播图
    @ApiOperation(value = "添加轮播图")
    @ApiImplicitParam(name = "setting",value = "设置",required = true)
    @PostMapping("/addRotationChart")
    public ResultMessage<Object> addRotationChart(@RequestBody RotationChart rotationChart){
        return ResultUtil.data(rotationChartMapper.insert(rotationChart));
    }

    //删除轮播图
    @ApiOperation(value = "删除轮播图")
    @ApiImplicitParam(name = "setting",value = "设置",required = true)
    @GetMapping("/deleteRotationChart/{id}")
    public ResultMessage<Object> deleteRotationChart(@PathVariable("id") Integer id){
        return ResultUtil.data(rotationChartMapper.deleteById(id));
    }
}
